package com.xiaoyu.lanling.feature.chat.viewholder

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageButton
import android.widget.TextView
import com.qmuiteam.qmui.widget.QMUILoadingView
import com.xiaoyu.im.datamodel.MessageDisplayStatus
import com.xiaoyu.lanling.R
import com.xiaoyu.lanling.feature.chat.handler.ChatMessageAudioItemClickHandler
import com.xiaoyu.lanling.feature.chat.model.message.ChatMessageSendAudioItem

class ChatMessageSendAudioViewHolder : ChatMessageBaseReceiveSendViewHolder<ChatMessageSendAudioItem>() {

    private var mView: View? = null
    private var mFail: ImageButton? = null
    private var mLoading: QMUILoadingView? = null
    private var mAudio: TextView? = null

    override fun doCreateChildrenView(layoutInflater: LayoutInflater, parent: ViewGroup): View? {
        mView = layoutInflater.inflate(R.layout.item_chat_send_audio, parent, false)
        mFail = mView?.findViewById(R.id.chat_send_fail)
        mLoading = mView?.findViewById(R.id.chat_send_loading)
        mAudio = mView?.findViewById(R.id.chat_message_audio)
        return mView
    }

    override fun showData(position: Int, itemData: ChatMessageSendAudioItem) {
        super.showData(position, itemData)

        if (itemData.messageDisplayStatus == MessageDisplayStatus.SENDING) {
            mLoading?.visibility = View.VISIBLE
            mFail?.visibility = View.GONE
        } else if (itemData.messageDisplayStatus == MessageDisplayStatus.NORMAL_FAIL) {
            mFail?.setImageResource(R.drawable.icon_chat_send_fail)
            mFail?.visibility = View.VISIBLE
            mLoading?.visibility = View.GONE
        } else if (itemData.messageDisplayStatus == MessageDisplayStatus.BLACKED_FAIL) {
            mFail?.setImageResource(R.drawable.icon_chat_check_fail)
            mFail?.visibility = View.VISIBLE
            mLoading?.visibility = View.GONE
        } else {
            mFail?.visibility = View.GONE
            mLoading?.visibility = View.GONE
        }
        val audioDuration: String = itemData.duration.toString() + "    "
        mAudio?.text = audioDuration

        mAudio?.let {
            ChatMessageAudioItemClickHandler.bindSendAudioItemClickForViewAndData(it, itemData)
            ChatMessageAudioItemClickHandler.bindSendAudioItemLongClickForViewAndData(it, itemData)
        }

//        ChatMessageSendFailClickHandler.bindAudioSendFailClickForViewAndData(mFail, itemData)
    }
}